package com.cruel_wandering.wifi_geo_predictor;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.DisplayMetrics;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyWiFiOverlay extends Overlay {
	private static final int million = 1000000;
	private static float radius;
	
    private double lng;
    private double lat;
    private Paint paint = new Paint();
    private DisplayMetrics dm = new DisplayMetrics();
    private Context ctx;

    public MyWiFiOverlay(double latSrc, double lngSrc, float radiusSrc, DisplayMetrics dmSrc, Context ctxSrc) {
    	lat = latSrc;
    	lng = lngSrc;
        paint.setARGB(50, 75, 0, 200);
        dm.setTo(dmSrc);
        ctx = ctxSrc;
        radius = radiusSrc;
    }

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {	
		Projection projection = mapView.getProjection();
		double zoom = MapScreen.maxZoom - mapView.getZoomLevel();
		int r = (int) ((radius * dm.widthPixels) /
				(MapScreen.minSpan * Math.pow(MapScreen.zoomCoeff, zoom)));
		if(r == 0) r = 1;
		Point point = new Point();
		projection.toPixels(new GeoPoint((int)lat*million,
         		(int)lng*million), point );
		canvas.drawCircle(point.x, point.y, r, paint);
		//Logger.getInstance(ctx).log("WiFiOverlay", "radius in pixels : "+((Integer) r ).toString());
		//Logger.getInstance(ctx).log("WiFiOverlay", "dm.widthPixels: "+((Integer) dm.widthPixels ).toString());
		//Logger.getInstance(ctx).log("WiFiOverlay", "Zoom: "+((Integer) mapView.getZoomLevel()).toString());
		
		super.draw(canvas, mapView, shadow);
	}  
}